package com.hmall.api.client.fallback;

import com.hmall.api.client.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * UserClient服务限流或熔断后的降级策略
 */
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    /**
     * Returns an instance of the fallback appropriate for the given cause.
     *
     * @param cause cause of an exception.
     * @return fallback
     */
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public void deductMoney(String pw, Integer amount) {
                log.error("UserClient.deductMoney()方法执行失败！抛出异常");
                throw new RuntimeException(cause);
            }
        };
    }
}
